<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-baseInfo-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">姓名：</label>
				<div class="col-sm-8">
					<input id="empNm" name="empNm" class="form-control" type="text">
				</div>
			</div>
			<!-- 居民身份证,军人证,护照,境外永久居住证,香港特区护照/身份证明,澳门特区护照/身份证明,台湾居民来往大陆通行证,其他 -->
			<div class="form-group">
				<label class="col-sm-3 control-label">证件类型：</label>
				<div class="col-sm-8">
					<select id="empIdType" class="form-control m-b" th:with="type=${@dict.getType('pm_card_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">证件号码：</label>
				<div class="col-sm-8">
					<input id="empId" name="empId" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">手机号码：</label>
				<div class="col-sm-8">
					<input id="empTel" name="empTel" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">性别：</label>
				<div class="col-sm-8">
					<select id="empSex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属公司名称：</label>
				<div class="col-sm-8">
					<input id="empComp" name="empComp" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">人员技能及特长：</label>
				<div class="col-sm-8">
					<textarea type="text" id="empSkills" name="empSkills" class="form-control" placeholder="请输入文本" rows="10"></textarea>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "pm/baseInfo";
		$("#form-baseInfo-add").validate({
			rules:{
				empId:{
        			required:true,
        			maxlength: 20,
        			remote: {
                        url: prefix + "/checkEmpIdUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#empId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		empNm:{
        			required:true
        		},
        		empTel:{
        			required:true,
                    isPhone:true
        		},
        		empIdType:{
        			required:true
        		},
        		empComp:{
        			required:true
        		},
                empSkills:{
                    required:true
				}
        	},
        	messages: {
                "empId": {
                    remote: "证件号码已经存在"
                }
            }
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            add();
	        }
	    }
		
		function add() {
			var empId = $("input[name='empId']").val();
        	var empNm = $("input[name='empNm']").val();
        	var empTel = $("input[name='empTel']").val();
        	var empIdType = $("#empIdType option:selected").val();
        	var empSex = $("#empSex option:selected").val();
        	var empComp = $("input[name='empComp']").val();
        	var empSkills = $("textarea[name='empSkills']").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "pm/baseInfo/add",
        		data : {
        			"empId": empId,
        			"empNm": empNm,
        			"empTel": empTel,
        			"empIdType": empIdType,
        			"empSex": empSex,
        			"empComp": empComp,
        			"empSkills": empSkills
        		},
        		async : true,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
	</script>
</body>
</html>
